package cn.edu.xmut.chen.zhlg.zhlg.vacancy.service.impl;

import cn.edu.xmut.chen.zhlg.zhlg.vacancy.entity.Collect;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.mapper.CollectMapper;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.param.CollectParam;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.result.CollectResult;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.result.VacancyPageResult;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.service.CollectService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import cn.edu.xmut.chen.zhlg.zhlg.vacancy.service.VacancyService;

@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Autowired
    private VacancyService vacancyService;

    @Autowired
    private CollectMapper collectMapper;

    @Override
    public Page<CollectResult> getCollectedVacanciesByUserId(CollectParam param) {
        // 1. 查询用户的所有收藏记录
        List<Collect> collects = this.lambdaQuery().eq(Collect::getUserId, param.getUserId()).list();

         if (collects == null || collects.isEmpty()) {
            return null;
        }
        if(param.getPageNum() == null){
            param .setPageNum(1);
        }
        if(param.getPageSize() == null){
            param.setPageSize(10);
        }

        Page<CollectResult> page = new Page<>(param.getPageNum(), param.getPageSize());
        return collectMapper.pageSearch(page, param.getUserId());
    }
} 